package main.java.cn.zjgsu.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;





import java.util.ArrayList;
import java.util.List;

import main.java.cn.zjgsu.domain.Resume;
import main.java.cn.zjgsu.domain.Student;
import main.java.cn.zjgsu.util.JdbcUtil;


public class Dao {
	public Student findStudent(String username,String password) throws Exception {
		Connection conn =null;
		    Statement stmt =null;
		    ResultSet rs=null;
		    
		    try{
		    	conn =(Connection) JdbcUtil.getConnection();
		    	  stmt =(Statement) conn.createStatement();
		    	  rs=stmt.executeQuery("select * from stu_user where no='"+username+"' and password='"+password+"'");
		    	 
		    	  if(rs.next()){
		    	      Student student=new Student();
		    	      student.setNo(rs.getString("no"));
		    	      student.setPassword(rs.getString("password"));
		    	       return student;
		    	}
		    	  else
		    		{return null;}
		    }catch(Exception e){
		    	 throw new Exception(e);
	    	  } finally
	    	  {
	    		  JdbcUtil.release(rs,stmt,conn);
	    	
	    	  }
		
	}
	
	

public void findStudentinfo(String no) throws Exception {
	// TODO Auto-generated method stub
	Connection conn =null;
    Statement stmt =null;
    ResultSet rs=null;
 
   // List<Student> list=new ArrayList<Student>();
    try{
    	conn =(Connection) JdbcUtil.getConnection();
    	  stmt =(Statement) conn.createStatement();
    	  
    		  
    		  
    		  rs=stmt.executeQuery("select * from stu_info where no ='"+no+"'");
    	
    	
    	  while(rs.next()){
    	      Student student=new Student();
    	      student.setNo(rs.getString("no"));
    	      student.setName(rs.getString("name"));
    	      student.setJidian(rs.getString("jidian"));
    	      student.setAddress(rs.getString("address"));
    	      student.setSex(rs.getString("sex"));
    	      student.setNatv(rs.getString("natv"));
    	      student.setBirthday(rs.getDate("birthday"));
    	      student.setGuanji(rs.getString("guanji"));
    	      student.setZhengzhi(rs.getString("zhengzhi"));
    	      student.setPhone(rs.getString("phone"));
    	      student.setEmail(rs.getString("email"));
    	      student.setGlory(rs.getString("glory"));
    	      
    	    //  list.add(student);
    	      
    	     
    	      
    	    } 
    	  
    }catch(Exception e){
    	 throw new Exception(e);
	  } finally
	  {
		  JdbcUtil.release(rs,stmt,conn);
	
	  }


	
}


public void updateResume(String no,String txt,String introduce,String resname) {
	// TODO Auto-generated method stub
	Connection conn =null;
    Statement stmt =null;
    ResultSet rs=null;
    try{
    	conn =(Connection) JdbcUtil.getConnection();
    	
  	    stmt =(Statement) conn.createStatement();
  	    stmt.executeUpdate("update resumes set resname='"+txt+"',introduce='"+introduce+"' where resname ='"+resname+"' and no='"+no+"'");
    	}
    catch(Exception e){
    	
    	
    }
    finally{
    	 JdbcUtil.release(rs,stmt,conn);
    	
    	
    }
	
   
	
}
public Student addResumesByno(String no,String txt,String state) throws Exception {
	Connection conn =null;
    Statement stmt =null;
    try{
    	conn =(Connection) JdbcUtil.getConnection();
    	stmt =(Statement) conn.createStatement();
   	stmt.executeUpdate("insert into resumes (resname,introduce,no) values('"+txt+"','"+state+"','"+no+"')");
     	   
   	}    	 
    catch(Exception e){
   	 throw new Exception(e);
   	  } finally
   	  {
   		  JdbcUtil.release(null,stmt,conn);
   	  }
	return null;
	
	
}

public void findResumes(String no) throws Exception {
	Connection conn =null;
    Statement stmt =null;
    ResultSet rs=null;
   // List<Student> list=new ArrayList<Student>();
    //List<Resume> list=new ArrayList<Resume>();
    try{
    	conn =(Connection) JdbcUtil.getConnection();
    	  stmt =(Statement) conn.createStatement();
    	  
    		  
    		  
    		  rs=stmt.executeQuery("select * from resumes where no ='"+no+"'");
    	
    	
    	  while(rs.next()){
    	      Resume resume=new Resume();
    	      resume.setResname(rs.getString("resname"));
    	      resume.setIntroduce(rs.getString("introduce"));
    	      //resume.add(resume);
    	      
    	     
    	      
    	    } 
    	  
    }catch(Exception e){
    	 throw new Exception(e);
	  } finally
	  {
		  JdbcUtil.release(rs,stmt,conn);
	
	  }
     

	//return list;
}
public void delResume(String resname,String no) {
	// TODO Auto-generated method stub
	Connection conn =null;
    Statement stmt =null;
    ResultSet rs=null;

    try{
    	conn =(Connection) JdbcUtil.getConnection();
  	    stmt =(Statement) conn.createStatement();
  	    stmt.executeUpdate("DELETE FROM resumes where resname ='"+resname+"'and no='"+no+"'");
    	}
    catch(Exception e){
    	//throw new DaoException(e);
    	
    }
    finally{
    	 JdbcUtil.release(rs,stmt,conn);
    	
    	
    }
}
}